{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "featurescore/feature_score_28.csv\n",
      "featurescore/feature_score_18.csv\n",
      "featurescore/feature_score_22.csv\n",
      "featurescore/feature_score_7.csv\n",
      "featurescore/feature_score_1.csv\n",
      "featurescore/feature_score_9.csv\n",
      "featurescore/feature_score_17.csv\n",
      "featurescore/feature_score_5.csv\n",
      "featurescore/feature_score_34.csv\n",
      "featurescore/feature_score_3.csv\n",
      "featurescore/feature_score_32.csv\n",
      "featurescore/feature_score_16.csv\n",
      "featurescore/feature_score_24.csv\n",
      "featurescore/feature_score_30.csv\n",
      "featurescore/feature_score_15.csv\n",
      "featurescore/feature_score_29.csv\n",
      "featurescore/feature_score_25.csv\n",
      "featurescore/feature_score_12.csv\n",
      "featurescore/feature_score_27.csv\n",
      "featurescore/feature_score_31.csv\n",
      "featurescore/feature_score_6.csv\n",
      "featurescore/feature_score_26.csv\n",
      "featurescore/feature_score_14.csv\n",
      "featurescore/feature_score_11.csv\n",
      "featurescore/feature_score_35.csv\n",
      "featurescore/feature_score_10.csv\n",
      "featurescore/feature_score_4.csv\n",
      "featurescore/feature_score_13.csv\n",
      "featurescore/feature_score_33.csv\n",
      "featurescore/feature_score_19.csv\n",
      "featurescore/feature_score_23.csv\n",
      "featurescore/feature_score_8.csv\n",
      "featurescore/feature_score_2.csv\n",
      "featurescore/feature_score_21.csv\n",
      "featurescore/feature_score_0.csv\n",
      "featurescore/feature_score_20.csv\n"
     ]
    }
   ],
   "source": [
    "files = os.listdir('featurescore')\n",
    "fs = {}\n",
    "for f in files:\n",
    "    print('featurescore/'+f)\n",
    "    t = pd.read_csv('featurescore/'+f)\n",
    "    t.index = t.feature\n",
    "    t = t.drop(['feature'],axis=1)\n",
    "    d = t.to_dict()['score'] # t.to_dict()是以列名作为做外层的key值\n",
    "    for key in d:\n",
    "        if fs. __contains__(key):\n",
    "            fs[key] += d[key]\n",
    "        else:\n",
    "            fs[key] = d[key] \n",
    "            \n",
    "fs = sorted(fs.items(), key=lambda x:x[1],reverse=True)\n",
    "\n",
    "t = []\n",
    "for (key,value) in fs:\n",
    "    t.append(\"{0},{1}\\n\".format(key,value))\n",
    "\n",
    "with open('feature_score.csv','w') as f:\n",
    "    f.writelines(\"feature,score\\n\")\n",
    "    f.writelines(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
